package cn.com.w.dao.Service.Impl;


import cn.com.w.common.VO.BaseVO;
import cn.com.w.dao.Entity.SysUser;
import cn.com.w.dao.Service.ISysUserService;
import cn.com.w.dao.Service.RegisterJudgeService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.regex.Pattern;

/**
 * @author w
 * @Description:
 * @DateTime: 2025 05 07 19:46
 **/
@Service
public class PhoneJudgeServiceImpl implements RegisterJudgeService {
    private final ISysUserService userService;

    @Autowired
    public PhoneJudgeServiceImpl( ISysUserService userService) {
        this.userService = userService;
    }

    @Override
    public void check(String other) throws Exception {
        String regex = "^1[3-9]\\d{9}$";
        if (!Pattern.matches(regex, other)) {
            BaseVO.error("手机号不符合规则！");
        }
        LambdaQueryWrapper<SysUser> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(SysUser::getPhoneNumber, other);
        if (userService.count(wrapper) > 0) {
            BaseVO.error("已存在相同手机号！");
        }
    }
}